/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#include "node/exception.h"

#include <typeinfo>
#include "node/util/error.h"

namespace node {
    using namespace ::node::util::error;

    Exception::Exception(void)
        : code_(errcode())
        , msg_()
    {
        errstr(code_, msg_);
    }

    Exception::Exception(int code)
        : code_(code)
        , msg_()
    {
        errstr(code_, msg_);
    }

    Exception::Exception(const std::string& msg, int code)
        : code_(code)
        , msg_(msg)
    {

    }

    Exception::~Exception(void) throw ()
    {

    }

    //-------------------------------------------------------------------------
    IMPLEMENT_EXCEPTION(LogicException, Exception, "Logic exception")
    IMPLEMENT_EXCEPTION(AssertionViolationException, LogicException, "Assertion violation")
    IMPLEMENT_EXCEPTION(NullPointerException, LogicException, "Null pointer")
    IMPLEMENT_EXCEPTION(NullValueException, LogicException, "Null value")
    IMPLEMENT_EXCEPTION(BugcheckException, LogicException, "Bugcheck")
    IMPLEMENT_EXCEPTION(InvalidArgumentException, LogicException, "Invalid argument")
    IMPLEMENT_EXCEPTION(NotImplementedException, LogicException, "Not implemented")
    IMPLEMENT_EXCEPTION(RangeException, LogicException, "Out of range")
    IMPLEMENT_EXCEPTION(IllegalStateException, LogicException, "Illegal state")
    IMPLEMENT_EXCEPTION(InvalidAccessException, LogicException, "Invalid access")
    IMPLEMENT_EXCEPTION(SignalException, LogicException, "Signal received")
    IMPLEMENT_EXCEPTION(UnhandledException, LogicException, "Unhandled exception")

}